var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    title:'我叫精品课',
    prices:100,
    time:'23:00',
    play:100,
    des:'法语是继西班牙文之后，使用者人数最多的罗曼语言独立语言之一。现时全世界有8700万人把它作为母语，以及其他2.85亿人使用它（包括把它作为第二语言的人）',
    commits:33,
    style:'color:#313131;font-size:15px;font-weight:normal;',
    poster:'',
    commetsArray: [],
    id:'',
    videoSrc:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    console.log(options)
    var id=options.id;
    this.setData({
      id:id
    })
   
  },
submit:function(event){
  var that=this
  var v=event.detail.v
  wx.request({
    url: app.globalData.baseUrl +'microvideo/video/comment',
    method:'POST',
    header:{
      'cookie':'JSESSIONID='+wx.getStorageSync('sessionID'),
      'content-type': 'application/x-www-form-urlencoded',
    },
    data:{
      videoId:that.data.id,
      content:v
    },
    success:function(res){
      console.log(res)
      that.onShow()
    }
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this
    wx.request({
      url: app.globalData.baseUrl + 'microvideo/video/' + that.data.id,
      method: 'get',
      header: {
        'cookie': 'JSESSIONID=' + wx.getStorageSync('sessionID')
      },
      success: function (res) {
        console.log(res)
      
        var resData = res.data.data
        var videoTime=parseInt(resData.videoAttribute.duration/1000)
        var videoTimeMinute=parseInt(videoTime/60)
        if (videoTimeMinute==0){
          videoTimeMinute=videoTimeMinute.toString()+'0'
        }
        var videoTimeSecond=parseInt(videoTime%60)
        var time=videoTimeMinute.toString()+':'+videoTimeSecond.toString()
        that.setData({
          time:time,
          title: resData.title,
          prices: resData.price,
          des: resData.description,
          commits: resData.commentList.length,
          play:resData.read,
          poster:resData.coverImg,
          videoSrc:resData.videoUrl
        })
        for(var i=0;i<resData.commentList.length;i++){
          var avatar='commetsArray['+i+'].avatar'
          var date = 'commetsArray[' + i + '].date'
          var content = 'commetsArray[' + i + '].content'
          var nickName='commetsArray['+i+'].nickName'
          
          that.setData({
            [avatar]: resData.commentList[i].user.avatarUrl,
            [date]: resData.commentList[i].gmtCreateFormat.substring(0,10),
            [content]: resData.commentList[i].content,
            [nickName]:resData.commentList[i].user.nickName
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})